using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the AspnetApplication class.
	/// </summary>
	[Serializable]
	public partial class AspnetApplicationCollection : ActiveList<AspnetApplication, AspnetApplicationCollection> 
	{	   
		public AspnetApplicationCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the aspnet_Applications table.
	/// </summary>
	[Serializable]
	public partial class AspnetApplication : ActiveRecord<AspnetApplication>
	{
		#region .ctors and Default Settings
		
		public AspnetApplication()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public AspnetApplication(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public AspnetApplication(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public AspnetApplication(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("aspnet_Applications", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarApplicationName = new TableSchema.TableColumn(schema);
				colvarApplicationName.ColumnName = "ApplicationName";
				colvarApplicationName.DataType = DbType.String;
				colvarApplicationName.MaxLength = 256;
				colvarApplicationName.AutoIncrement = false;
				colvarApplicationName.IsNullable = false;
				colvarApplicationName.IsPrimaryKey = false;
				colvarApplicationName.IsForeignKey = false;
				colvarApplicationName.IsReadOnly = false;
				colvarApplicationName.DefaultSetting = @"";
				colvarApplicationName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApplicationName);
				
				TableSchema.TableColumn colvarLoweredApplicationName = new TableSchema.TableColumn(schema);
				colvarLoweredApplicationName.ColumnName = "LoweredApplicationName";
				colvarLoweredApplicationName.DataType = DbType.String;
				colvarLoweredApplicationName.MaxLength = 256;
				colvarLoweredApplicationName.AutoIncrement = false;
				colvarLoweredApplicationName.IsNullable = false;
				colvarLoweredApplicationName.IsPrimaryKey = false;
				colvarLoweredApplicationName.IsForeignKey = false;
				colvarLoweredApplicationName.IsReadOnly = false;
				colvarLoweredApplicationName.DefaultSetting = @"";
				colvarLoweredApplicationName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLoweredApplicationName);
				
				TableSchema.TableColumn colvarApplicationId = new TableSchema.TableColumn(schema);
				colvarApplicationId.ColumnName = "ApplicationId";
				colvarApplicationId.DataType = DbType.Guid;
				colvarApplicationId.MaxLength = 0;
				colvarApplicationId.AutoIncrement = false;
				colvarApplicationId.IsNullable = false;
				colvarApplicationId.IsPrimaryKey = true;
				colvarApplicationId.IsForeignKey = false;
				colvarApplicationId.IsReadOnly = false;
				
						colvarApplicationId.DefaultSetting = @"(newid())";
				colvarApplicationId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApplicationId);
				
				TableSchema.TableColumn colvarDescription = new TableSchema.TableColumn(schema);
				colvarDescription.ColumnName = "Description";
				colvarDescription.DataType = DbType.String;
				colvarDescription.MaxLength = 256;
				colvarDescription.AutoIncrement = false;
				colvarDescription.IsNullable = true;
				colvarDescription.IsPrimaryKey = false;
				colvarDescription.IsForeignKey = false;
				colvarDescription.IsReadOnly = false;
				colvarDescription.DefaultSetting = @"";
				colvarDescription.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDescription);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("aspnet_Applications",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("ApplicationName")]
		public string ApplicationName 
		{
			get { return GetColumnValue<string>("ApplicationName"); }

			set { SetColumnValue("ApplicationName", value); }

		}

		  
		[XmlAttribute("LoweredApplicationName")]
		public string LoweredApplicationName 
		{
			get { return GetColumnValue<string>("LoweredApplicationName"); }

			set { SetColumnValue("LoweredApplicationName", value); }

		}

		  
		[XmlAttribute("ApplicationId")]
		public Guid ApplicationId 
		{
			get { return GetColumnValue<Guid>("ApplicationId"); }

			set { SetColumnValue("ApplicationId", value); }

		}

		  
		[XmlAttribute("Description")]
		public string Description 
		{
			get { return GetColumnValue<string>("Description"); }

			set { SetColumnValue("Description", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public Adex.AspnetMembershipCollection AspnetMembershipRecords()
		{
			return new Adex.AspnetMembershipCollection().Where(AspnetMembership.Columns.ApplicationId, ApplicationId).Load();
		}

		public Adex.AspnetRoleCollection AspnetRoles()
		{
			return new Adex.AspnetRoleCollection().Where(AspnetRole.Columns.ApplicationId, ApplicationId).Load();
		}

		public Adex.AspnetUserCollection AspnetUsers()
		{
			return new Adex.AspnetUserCollection().Where(AspnetUser.Columns.ApplicationId, ApplicationId).Load();
		}

		#endregion
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varApplicationName,string varLoweredApplicationName,Guid varApplicationId,string varDescription)
		{
			AspnetApplication item = new AspnetApplication();
			
			item.ApplicationName = varApplicationName;
			
			item.LoweredApplicationName = varLoweredApplicationName;
			
			item.ApplicationId = varApplicationId;
			
			item.Description = varDescription;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varApplicationName,string varLoweredApplicationName,Guid varApplicationId,string varDescription)
		{
			AspnetApplication item = new AspnetApplication();
			
				item.ApplicationName = varApplicationName;
				
				item.LoweredApplicationName = varLoweredApplicationName;
				
				item.ApplicationId = varApplicationId;
				
				item.Description = varDescription;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ApplicationName = @"ApplicationName";
			 public static string LoweredApplicationName = @"LoweredApplicationName";
			 public static string ApplicationId = @"ApplicationId";
			 public static string Description = @"Description";
						
		}

		#endregion
	}

}

